//
//  XNHud.m
//  XINNingOA
//
//  Created by samuel on 2021/7/12.
//

#import "XNHud.h"

@implementation XNHud

+ (MBProgressHUD*)showToastWithText:(NSString *)text{
    return [self showToastWithText:text hiddenDelay:3];
}
+ (MBProgressHUD*)showToastWithText:(NSString *)text hiddenDelay:(NSTimeInterval)delay{
    return [self showToastWithText:text hiddenDelay:delay completeBlock:nil];
}
+ (MBProgressHUD*)showToastWithText:(NSString *)text hiddenDelay:(NSTimeInterval)delay completeBlock:(MBProgressHUDCompletionBlock)complete{
    UIWindow *window = [UIApplication sharedApplication].windows.lastObject;
    return [self showToastOn:window withText:text hiddenDelay:delay completeBlock:complete];

}
+ (MBProgressHUD*)showToastOn:(UIView *)toView withText:(NSString *)text{
  
    return [self showToastOn:toView withText:text hiddenDelay:1.5];
}
+ (MBProgressHUD*)showToastOn:(UIView *)toView withText:(NSString *)text hiddenDelay:(NSTimeInterval)delay{
    return [self showToastOn:toView withText:text hiddenDelay:delay completeBlock:nil];
}
+ (MBProgressHUD*)showToastOn:(UIView *)toView withText:(NSString *)text hiddenDelay:(NSTimeInterval)delay completeBlock:(MBProgressHUDCompletionBlock)complete{
    MBProgressHUD *hud = [self hudAddTo:toView withText:text completeBlock:complete];
    [hud hideAnimated:NO afterDelay:delay];
    return hud;
}
+ (MBProgressHUD *)hudAddTo:(UIView *)toView withText:(NSString *)text  completeBlock:(MBProgressHUDCompletionBlock)complete{
    
    [MBProgressHUD hideHUDForView:toView animated:YES];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:toView animated:YES];
    [toView bringSubviewToFront:hud];
    hud.layer.cornerRadius = 4;
    hud.clipsToBounds = YES;
//    hud.offset = CGPointMake(0, SCREEN_HEIGHT/2 - 124 * SCREEN_HEIGHT/667);
//    [hud setYOffset:SCREEN_HEIGHT/2 - 124 * SCREEN_HEIGHT/667];
    [hud setMargin:12];
    [hud setMode:MBProgressHUDModeText];
    hud.label.font = [UIFont systemFontOfSize:14];
//    hud.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
//    [hud setColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.6]];
//    [hud setLabelFont: NAFFontRegular(14)];
    [hud setCompletionBlock:complete];
    hud.label.text = text;
//    [hud setLabelText:text];
    return hud;


}

+ (MBProgressHUD *)showProgressOn:(UIView*)view withText:(NSString *)text mode:(MBProgressHUDMode)mode{
      MBProgressHUD *hud = [self hudAddTo:view withText:text completeBlock:nil];
    [hud setMode:mode];
//    [hud setYOffset:0];
    return hud;
    
}

+ (MBProgressHUD *)hudForKeyWindow{
    UIWindow *winndow = [UIApplication sharedApplication].windows.lastObject;
    return [MBProgressHUD HUDForView:winndow];
}
+ (MBProgressHUD *)showProgressWithText:(NSString *)text{
    UIWindow *winndow = [UIApplication sharedApplication].windows.lastObject;
    return [self showProgressOn:winndow withText:text];
}

+ (void)showProgress
{
    UIWindow *winndow = [UIApplication sharedApplication].windows.lastObject;
    [self showProgressOn:winndow withText:@"加载中"];
}

+ (void)hideProgress{
    UIWindow *winndow = [UIApplication sharedApplication].windows.firstObject;
    return [self hiddenToastOn:winndow];
}
+ (MBProgressHUD *)showProgressOn:(UIView*)view withText:(NSString *)text{
    return [self showProgressOn:view withText:text mode:MBProgressHUDModeIndeterminate];
}

+ (void)hiddenToastOn:(UIView *)view{
    [MBProgressHUD hideHUDForView:view animated:YES];
}

@end
